# coding: gbk

from django.http import HttpResponseRedirect, HttpResponse
from djangoext.mako import render_to_response , render_to_string, render_string

import time, datetime
import re
import cStringIO
import os
import random
import types, operator
from shangjie.utils import log, cache
from shangjie.utils import lunar

from shangjie.conf import settings
from sqlalchemy.sql import *

from functools import partial

from pyExcelerator import *

try:
    import uuid
except:
    import fake_uuid as uuid

import copy
from djangoext.urls import expose
from oa.utils import *
def save( req ):
    code = autowrite(req)
    log.info("code",code)
    flag, reqobj = get_reqobj( req )
    if not flag: return HttpResponse( {  'rspcode': 8004, 'rspinfo': reqobj } )
    rnid = reqobj.get('rnid','').decode('utf-8').encode('gbk')
    noticeTime = reqobj.get('noticeTime','').decode('utf-8').encode('gbk')
    cid = reqobj.get('cid','').decode('utf-8').encode('gbk')
    pcid = reqobj.get('pcid','').decode('utf-8').encode('gbk')
    web_token = reqobj.get('web_token','').decode('utf-8').encode('gbk')
    eid = reqobj.get('eid','').decode('utf-8').encode('gbk')
    time = reqobj.get('time','').decode('utf-8').encode('gbk')
    employeeName = reqobj.get('employeeName','').decode('utf-8').encode('gbk')
    pcName = GS_DICT.get(pcid,'').encode('gbk')
    cName = XQ_DICT.get(cid,'').encode('gbk')
    se = settings.DB_SESSION()
    content = {}
    _id = se.execute( " select IFNULL(max(_id),0)+1 from zhsq_dmsrn").fetchall()[0][0]
    rnid = "BMS%s%07d"%(datetime.datetime.now().strftime( '%Y%m%d' ),_id)
    sql =   "insert into zhsq_dmsrn (rnid,noticeTime,cid,pcid,eid,time,employeeName,pcName,cName) values('%s','%s','%s','%s','%s','%s','%s','%s','%s')" %(rnid,noticeTime,cid,pcid,eid,time,employeeName,pcName,cName)
    se.execute( sql.decode('gbk') )
    se.close()
    log.info("bmsrole",sql)
    content = {"code":0,"message":None,"result":None,"exception":None}
    return HttpResponse( sjapi.jsondumps( content , ensure_ascii = False , encoding = 'utf-8' ), content_type='application/json; charset=gbk' )
    
